<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>NexHome Admin</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    

    <!-- libraries -->
   <link href="css/lib/jquery-ui-1.10.2.custom.css" rel="stylesheet" type="text/css" />
    <link href="css/lib/font-awesome.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
	
	<link rel="stylesheet" href="css/cfgmgr/bootstrap-table.css">    
 <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/index.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="css/cfgmgr/clean.css" type="text/css" media="screen" /> 
   
   <!-- open sans font -->
    <link href='css/OpenSans.css' rel='stylesheet' type='text/css' />

    <!-- lato font -->
    <link href='css/Lato.css' rel='stylesheet' type='text/css' />
	
<!--[if lt IE 9]>
      <script src="js/html5.js"></script>
    <![endif]--> 
	
	 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	 <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="0" />
	<meta http-equiv="Cache" content="no-cache">
  
<style>
	a{cursor:pointer;	
text-decoration: none;
}
	.icon-add {
width: 20px;
height: 20px;
background: url(images/icon_add.png) no-repeat;
font-size: 12px;
}
input.input-small {
width: 90%;
margin-top: 10px;
margin-right: 5px;
}
.Boardtab {
margin-bottom: 0 !important;
border: 1px solid #dddddd;
border-collapse: collapse !important;
border-radius: 1px;
}
.Boardtab tr{

border: 1px solid #dddddd;
border-collapse: collapse !important;
border-radius: 1px;
}
.Boardtab thead th {
padding: 8px;
line-height: 24px;
vertical-align: top;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.text-error {
color: #ff7d73;
font: 14px/20px "宋体",Arial, Helvetica, sans-serif;
}

input.error, textarea.error, select.error {
border-color: #ff7d73;
-webkit-box-shadow: 2px 2px 5px rgba(255,125,115,0.5),-2px -2px 5px rgba(255,125,115,0.5);
-moz-box-shadow: 1px 1px 1px rgba(255,125,115,0.5),-1px -1px 1px rgba(255,125,115,0.5);
box-shadow: 2px 2px 5px rgba(255,125,115,0.5),-2px -2px 5px rgba(255,125,115,0.5);
}
.modalTrigger.fade.in {
  /*top: 20%;*/
}
.modalSence.fade.in {
  /*top: 45%;*/
}


.modalAlarm.fade.in {
  /*top: 73%;*/
}
</style>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootbox.min.js"></script>
<script src="js/xml2json/ObjTree.js"></script>
<script src="js/xml2json/jkl-dumper.js"></script>

<script src="js/cfgmgr/map.js"></script>
<script src="js/cfgmgr/paramType2Map.js"></script>
<script src="js/cfgmgr/InitObjData.js"></script>
<script src="js/cfgmgr/LoadCfgData.js"></script>
<script src="js/cfgmgr/table/bootstrap-table.js"></script>
<script src="js/cfgmgr/table/bootstrap-table-zh-CN.js"></script>
<script src="js/bootbox.min.js"></script>
<script src="js/cfgmgr/cfgmgr.js"></script>
<script src="js/cfgmgr/validateInput.js"></script>
<script src="js/cfgmgr/validatesmall.js"></script>
<!--<script src="js/cfgmgr/Addplaceholder.js"></script>-->
<script src="js/cfgmgr/TriggerOpreator.js"></script>
<script src="js/cfgmgr/TablesOpretor.js"></script>
<script src="js/cfgmgr/CMDOpreator.js"></script>
<script src="js/cfgmgr/SenceOpreator.js"></script>
<script src="js/cfgmgr/alarmOprator.js"></script>		
<script src="js/cfgmgr/FormatToJsonData.js"></script>

<script>
$.fn.serializeObject = function()
{
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
var epidint = 0;
var scesetint = 0;
var areaidint = 0;
var triggeridint = 0;
var AlarmZoneidint = 0;
var Alarmidint = 0;
var AlarmAreaidint = 0;
var currusername;
var currfloorid = '';
var curralarmid = '';
var floorid;
var area_data;
var firstNavLiIds;
var NavLiIds=new Array();
var tableIds=new Array();
var currDelTriggerIds = "";
function request()
{ 
	var url = location.href;
	var paraString;
	if(url.indexOf("devid") != -1){ 
 	paraString = url.substring(url.indexOf("=")+1,url.length);	 
	}
	else{
	paraString = "NO";
	}
	return paraString;  	
	
}
function AddEpAction(currareaname)  //this currareaname == atype
{
	
	var ty = $('#conf').val();
	if(ty == '02'){
		$('#modelcode').val('00');
		$('#protocol').val('00');
	}
	var ey = $('#etype').val();
	var cy = $('#ctrltype').val();
	//var md =  $('#model').val();
	//$('#etypename').val(elemTypeMap.get(ey));
	$('#floorname').val(CurrfloorMap.get(currfloorid));
	$('#atypename').val(CurrAreaNameMap.get(currareaname));	
	$('#ctypename').val(ctrlTypeMap.get(cy));
	//$('#modelname').val(ModelTypeMap.get(md));
	if(cy == 3){
		$('#devtype').val("");
		$('#dtypename').val("");
	}
	else{
		var dy = $('#devtype').val();
		$('#dtypename').val(GetDtypeNameByCurrCtype(cy, dy));
		$('#devtype').attr("validate", "required");
	}
	//$('#epid').val(epidint);
	$('#floorid').val(currfloorid);
	$('#atype').val(currareaname); //elem里的atype即为area对象里的id
	//$('#conf').val("1");
	var mc = $('#modelcode').val();
	var pc = $('#protocol').val();
	var md = "0x"+ty+ey+mc+pc;
	//var alarmmd = "0x"+ty+ey+mc;
	var alarmmd = "0x"+ty+ey;
	var illuminationsmd = "0x"+ty+ey;
	$('#model').val(md);
	var ispass = validateRow('epAddModaltable');
	if(!ispass){
		
		return;
	}
	else{
	
		 var isAlready = false;
		 var ctrltype = $('#ctrltype').val();
		 var ctrlid = $('#ctrlid').val();
		 var devtype = $('#devtype').val();
		 var ctrlid = $('#ctrlid').val();
		 var dchan = $('#dchan').val();
		 var addr1 = $('#addr1').val();
		 var addr2 = $('#addr2').val();
		 if(CurrElemArry.length != 0){
			var Cur = [];
			Cur = $.grep(CurrElemArry,function(item, index){
														   
				if(item.ctrltype == ctrltype && item.ctrlid == ctrlid && item.devtype == devtype && item.dchan == dchan && item.addr1 == addr1 && item.addr2 == addr2)
					return true;
			},false);
			if(Cur.length != 0)
				isAlready = true;
		 }
		 
		 if(isAlready == true)
		 {
			var errorMsg = "该通道和地址的设备已经存在";
			$('#dchan').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
			return false;
		 }else{
		 	
			if(illuminationsmd == '0x0102'){
				var shape=$("#shape").children("option:selected").val();
				if(shape == '3'){				
					var disval = $('#distrib1').val() + ',' + $('#distrib2').val() + ',' + $('#distrib3').val() + ',' + $('#distrib4').val();
					}
				else{
					 var disval = '0';
					 $('#dir').val('0');
					 }
				
				$('#distrib').val(disval);
				$('#count').val(addr2);
			}
		 	epidint ++;
			parseInt(epidint);
			$('#epid').val(epidint);
			var table = $('#epAddModalform').serializeObject();	
			CurrElemArry.push(table);
				
			$('#epAddModal').modal('hide');
			$('#table'+currareaname).bootstrapTable('load',{data:GetCurrAreEleData(currfloorid,currareaname)});
			/*添加命令模板*/
			if(GetCurrModelObj.length != 0){
				var facmodel,cmdctype,cmdrw,cmdi;
				var etype=$("#etype").children("option:selected").val();
				var curcmdid=$("#modelselect").children("option:selected").val();
				var CurModelArray=GetCurModelArrayData(etype);
				var CurCmdArray=GetCurCmdArrayData(CurModelArray);
				$.each(CurCmdArray, function (index, item) {
					if(item.cid==curcmdid){
						cmdctype=item.ctype;
						cmdrw=item.rw;
						cmdi=item.i;
						facmodel=item.model;
					}
				});
				if (typeof(cmdrw) == 'undefined') {
				    cmdrw = 2;
				    cmdctype = 0;
				}
				else {
				    CurrElemCMDArry.push({"epid": epidint,"ctype": cmdctype,"rw": cmdrw,"mcmd":{"i":cmdi},"ccmd":{"i":"0"}});
				}				
			}
			/*添加报警主机节点*/
			//if(alarmmd == '0x011101'){
			if(alarmmd == '0x0111'){
				 Alarmidint ++;
				 parseInt(Alarmidint);
				 var name = $('#etypename').val();
				 CurrAlarmElemMap.put(Alarmidint, name);
				 CurrAlarmsArry.push({"id": Alarmidint,"epid": epidint,"name": name,"type": mc,"area": 0});
				 if(curralarmid == '' || curralarmid == null || curralarmid == undefined)
				 	curralarmid = Alarmidint;
				 LoadAlarmsIdSelect(curralarmid);
				 $('#AlarmAreaListTable').bootstrapTable('load',{data:GetCurrAlarmAreaData(curralarmid)});
			}
			
		}
	}
	
}
/*模态框内的表格操作*/

//删除行
function deleteRow(obj) {
		$.fn.tables.deleteRow(obj);
}

//增加行
function addTableRow(gridId) {
	$.fn.tables.addRow(gridId);
}
 //取结果
function getRowResult(tableid)
{
	var data=[];
	data = $.fn.tables.getResult(tableid);
	return data;
	
}
//校验
function validateRow(tableid)
{
    var ispass = $.fn.tables.validateRow(tableid);
     return ispass;
}
function addTriggerRow(gridId) {
	$.fn.tables.addTriggerRow(gridId);
}
function deleteTriggerRow(obj) {
		 if(confirm("删除该行将在点击‘保存’后会直接删除该触发条件下的所有联动内容，确定要删除吗？"))
			$.fn.tables.deleteTriggerRow(obj);
		 else
		 	return false;
}
/*报警器*/
function addAlarmAreaTableRow(gridId) {
	$.fn.tables.addAlarmAreaRow(gridId);
}
function addAlarmAreaZoneTableRow(gridId) {
	$.fn.tables.addAlarmAreaZoneTableRow(gridId);
}


function addCMDTypetableRow(obj)
{
	
	
	var cmdctypeid = $('#cmdctype').val();
	var cmdctypename = $('#cmdctype').find("option:selected").text();
	if(cmdctypeid == '')
	{
		alert("请选择命令类型");
		return;
	}
	var tbRow = "<tr><td><input type='text'  class='small' name='ctype' id='ctype'  readonly='true' value='"+cmdctypeid+"'></td><td><input type='text'  class='small' name='name' id='name' readonly='true' value='"+cmdctypename+"'></td><td style='display:none'><input type='text'  class='small' name='i' id='i'  value='0' readonly='true' ></td><td align='center'><a  title='编辑命令'   onClick='GetCMDFrom(this)'><i class='icon-edit'></i></a></td><td><a  title='删除'  onClick='deleteCMDTypeRow(this)'><i class='icon-remove'></i></a></td></tr>";		
	
	$("#CMDTypeListtable tbody").append(tbRow);
	
	

}
function addSceneGroupListtableRow(obj)
{
	
	var sceneTypeid = $('#sceneType').val();
	var sceneTypename = $('#sceneType').find("option:selected").text();
	if(sceneTypeid == '')
	{
		alert("请选择场景类型");
		return;
	}
	if(sceneTypeid == '999')
	{
		var ispass = validateRow('OtherSceneTypeView');
		if(!ispass){
			$.formSmallInit();
			
			return;
		}
	    sceneTypename = $('#sceneTypeName').val();
	}
		
		var tbRow = "<tr ><td><input type='text'  class='small' name='id' id='id'  readonly='true' value='"+sceneTypeid+"'></td><td><input type='text'  class='small' name='name' id='name' readonly='true' value='"+sceneTypename+"'></td><td style='display:none' ><input type='text'  class='small' name='i' id='i'  readonly='true' value='0'></td><td><a  title='删除'   onClick='deleteRow(this)'><i class='icon-remove'></i></a></td></tr>";
		$("#SceneGroupListtable tbody").append(tbRow);
	
	
}
function init()
{

	$("#div_find").hide();
	$("cfgShow").show();
	$('#currRouterid').html("当前路由器nid:" + currusername);
	//GetparamTypexmlTjson();
	
	 
	initSelect(currusername);
	initAreaType(currusername,currfloorid);	
	$('#myTab a:first').tab('show');
}
function McPtTrSwitch(currconf)
{
	if(currconf == '02'){
		$('#modelcode').val('00');
		$('#protocol').val('00');
		$('#modelcodeTr').hide();
		$('#protocolTr').hide();
	}else{
		$('#modelcodeTr').show();
		$('#protocolTr').show();
		
	}
}
function GetDtypeNameByCurrCtype(currctype, currdtype)
{
	if(currctype == 1 ){
		return LONinterfaceTypeMap.get(currdtype);
		
	}
	else if(currctype == 2 ){
		return l880interfaceTypeMap.get(currdtype);
		
	}
	else if(currctype == 4 ){
		return NICODMX512interfaceTypeMap.get(currdtype);
		
	}
	else if(currctype == 5 ){
		return l830linterfaceTypeMap.get(currdtype);
		
	}
	else{
		return null;
	}
}
function DtypeInitByCtypeChange(currctype)
{
	$("#epAddModaltable #dchanTr td").remove();
	var TextTd = "<td>设备通道</td><td><input type='text' name='dchan' id='dchan' validate='required|integer' class='input-xlarge'></td>";
	var SelectTd = "<td>设备通道</td><td><select  name='dchan' id='dchan' class='input-xlarge' validate='required' ></select></td>";
	if(currctype == 1 ){
		FillSelect(LONinterfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","LON");
		$("#epAddModaltable #dchanTr").append(TextTd);
		$("#epAddModaltable #dchan").attr("placeholder","输入0~127");
		$('#epAddModaltable #dchan').removeAttr("validate");
		$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
		$('#dtypeTr').show();
	}
	else if(currctype == 2 ){
		FillSelect(l880interfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","L880");
		$("#epAddModaltable #dchanTr").append(SelectTd);
		InitDchanSelecthtml(GetCurrl880interfaceRangeData(1),'dchan');
		//$('#epAddModaltable #dchan').removeAttr("validate");
		//$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[8]");
		$('#dtypeTr').show();
	}
	else if(currctype == 4 ){
		FillSelect(NICODMX512interfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","NICODMX512");
		$("#epAddModaltable #dchanTr").append(TextTd);
		//$('#epAddModaltable #dchan').removeAttr("validate");
		//$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[256]");
		//$('#epAddModaltable #dchan').val("0");
		$('#epAddModaltable #dchan').val("0");
		$('#epAddModaltable #dchan').attr("readOnly","true");
		$('#dtypeTr').show();
	}
	else if(currctype == 5 ){
		FillSelect(l830linterfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","L830L");
		$("#epAddModaltable #dchanTr").append(SelectTd);
		InitDchanSelecthtml(GetCurrl830linterfaceRangeData(1),'dchan');
		//$('#epAddModaltable #dchan').removeAttr("validate");
		//$("#epAddModaltable #dchan").attr("validate","required");
		$('#dtypeTr').show();
	}
	else{
		$('#dtypeTr').hide();
		$("#epAddModaltable #dchanTr").append(TextTd);
	}
}
function DtypeInitNoChooseByCtypeChange(currctype)
{
	if(currctype == 1 ){
		FillNoChoosedSelect(LONinterfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","LON");
		$('#epAddModaltable #dchan').removeAttr("validate");
		$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
		$('#dtypeTr').show();
	}
	else if(currctype == 2 ){
		FillNoChoosedSelect(l880interfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","L880");
		$('#epAddModaltable #dchan').removeAttr("validate");
		$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[8]");
		$('#dtypeTr').show();
	}
	else if(currctype == 4 ){
		FillNoChoosedSelect(NICODMX512interfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","NICODMX512");
		$('#epAddModaltable #dchan').removeAttr("validate");
		$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[256]");
		$('#epAddModaltable #dchan').val("0");
		$('#dtypeTr').show();
	}
	else if(currctype == 5 ){
		FillNoChoosedSelect(l830linterfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","L830L");
		$('#epAddModaltable #dchan').removeAttr("validate");
		$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[3]");
		
		$('#dtypeTr').show();
	}
	else{
		$('#dtypeTr').hide();
	}
}
function DchanSetValidateByDtypeChange(currctype, currdtypevalue)
{
	$("#epAddModaltable #dchanTr td").remove();
	var TextTd = "<td>设备通道</td><td><input type='text' name='dchan' id='dchan' validate='required|integer' class='input-xlarge'></td>";
	var SelectTd = "<td>设备通道</td><td><select  name='dchan' id='dchan' class='input-xlarge' validate='required' ></select></td>";
	if(currctype == 1 ){
		$("#epAddModaltable #dchanTr").append(TextTd);
		switch(currdtypevalue){
			case 1:
			case 2:
			case 3:
				
				$("#epAddModaltable #dchan").attr("placeholder","输入0~127");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
				break;
			case 4:
				
				$("#epAddModaltable #dchan").attr("placeholder","输入0~26");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[27]");
				break;
			case 5:
			case 6:
			case 7:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~15");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[16]");
				break;
			case 8:
			case 9:
			case 10:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~31");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[32]");
				break;						
			default:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~127");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
				
		}
		
		$('#dtypeTr').show();
	}
	else if(currctype == 2 ){
		if(currdtypevalue == 4 || currdtypevalue == 5){
			$("#epAddModaltable #dchanTr").append(TextTd);

			$('#epAddModaltable #dchan').val("0");
			$('#epAddModaltable #dchan').attr("readOnly","true");
		}
		else{
			$("#epAddModaltable #dchanTr").append(SelectTd);
			InitDchanSelecthtml(GetCurrl880interfaceRangeData(currdtypevalue),'dchan');
			
		}
			
		$('#dtypeTr').show();
	}
	else if(currctype == 4 ){
		/*$("#epAddModaltable #dchanTr").append(TextTd);
		switch(currdtypevalue){
			
			case 1:
			case 3:
			case 4:
			case 5:
			case 6:
				$('#epAddModaltable #dchan').val("0");
				$('#epAddModaltable #dchan').attr("readOnly","true");
				break;
			case 2:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~255");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[256]");
				break;
			default:
				$('#epAddModaltable #dchan').val("0");
				$('#epAddModaltable #dchan').attr("readOnly","true");
				
		}*/
		if(currdtypevalue == 1){
			$("#epAddModaltable #dchanTr").append(TextTd);

			$('#epAddModaltable #dchan').val("0");
			$('#epAddModaltable #dchan').attr("readOnly","true");
		}
		else{
			$("#epAddModaltable #dchanTr").append(SelectTd);
			InitDchanSelecthtml(GetCurrNICODMX512interfaceRangeData(currdtypevalue),'dchan');
			
		}
		
		$('#dtypeTr').show();
	}
	else if(currctype == 5 ){		
		$("#epAddModaltable #dchanTr").append(SelectTd);
		InitDchanSelecthtml(GetCurrl830linterfaceRangeData(currdtypevalue),'dchan');					
			
		$('#dtypeTr').show();
	}
	else{
		$('#dtypeTr').hide();
		$("#epAddModaltable #dchanTr").append(TextTd);
	}
	
}
function RenderilluminationsInfo()
{
	var model = $("#modelselect").children("option:selected").attr("data-model");
	var checkStr = model.substring(0,6);
	
	if(checkStr == '0x0102')
	{
		$('#shapeTr').show();
		//$('#countTr').show();
		FillSelectSetCurVal(shapeTypeMap,'shape','1');	
		
		$('#dirTr').hide();
		$('#distribTr').hide();
	}
}
function RenderModelInfo()
{
	
	var model = $("#modelselect").children("option:selected").attr("data-model");
	var conf=model.substring(2,4);
	var mc=model.substring(6,8);
	var pt=model.substring(8,10);
	$("#modelcode").val(mc);
	$("#protocol").val(pt);
	$("#conf").val(conf);
	$("#conf"+" option[value='" + conf + "']").attr("selected","selected");
	$('#devModelTr').show();
	$('#modelcodeTr').hide();
	$('#protocolTr').hide();
	$('#confTr').hide();
	//var ischeckAddr1 = $("#modelselect").children("option:selected").attr("data-ischeckAddr1");
	//var ischeckAddr2 = $("#modelselect").children("option:selected").attr("data-ischeckAddr2");
	var addr1Name = $("#modelselect").children("option:selected").attr("data-addr1Name");
	var addr2Name = $("#modelselect").children("option:selected").attr("data-addr2Name");
	if(addr1Name == '0'){
		$('#addr1Tr').hide();
		$('#addr1Name').html("额外地址1");
		$('#addr1').val("0");
		
	}
	else{
		$('#addr1Tr').show();
		$('#addr1Name').html(addr1Name);
		$('#addr1').val("");
	}
	if(addr2Name == '0'){
		$('#addr2Tr').hide();
		$('#addr2Name').html("额外地址2");
		$('#addr2').val("0");
		
	}
	else{
		$('#addr2Tr').show();
		$('#addr2Name').html(addr2Name);
		$('#addr2').val("");
	}
		
}
$(function () {
$(document).bind("contextmenu",function(e){   
          return false;   
}); 
currusername = request();
	
if(currusername != 'NO'){ 

	$("#div_find").hide();
	$("cfgShow").show();
	$('#currRouterid').html("当前路由器NID:" + currusername);
	GetparamTypexmlTjson();

}
else{
	
	bootbox.alert("请从‘设备管理’的设备列表中选择设备点击跳入", function() {					
		parent.Reload_devList();
	});	
}
$.formInit();
$.formSmallInit();
//$.AddrplaceholderInit();
$('#etypename').val(elemTypeMap.get("01"));
DtypeInitByCtypeChange(1);
McPtTrSwitch('01');

$('#modelselect').change(function(e){
	e.preventDefault();
	var facmodel,cmdctype,cmdrw,cmdi;
	var etype=$("#etype").children("option:selected").val();
	RenderilluminationsInfo();
	var curcmdid=$("#modelselect").children("option:selected").val();
	if(curcmdid!= "" && curcmdid != undefined && curcmdid != null){
		RenderModelInfo();	
	}
	else{
		$('#devModelTr').hide();
		$('#modelcodeTr').show();
		$('#protocolTr').show();
		$('#confTr').show();
		$('#addr1').val("");
		$('#addr2').val("");
		$('#addr1Tr').show();
		$('#addr1Name').html("额外地址1");
		$('#addr2Tr').show();
		$('#addr2Name').html("额外地址2");
	}
});
 $('#etype').change(function(e){
	e.preventDefault();
	$('#etypename').val($('#etype').find("option:selected").text());
	var etype=$("#etype").children("option:selected").val();
	var CurModelArray=GetCurModelArrayData(etype);
	var CurCmdArray=GetCurCmdArrayData(CurModelArray);
	FillSelectCmdModel(CurCmdArray,'modelselect');
	var curcmdid=$("#modelselect").children("option:selected").val();
	if(curcmdid!= "" && curcmdid != undefined && curcmdid != null){
		RenderModelInfo();
	}
	else{
		$('#devModelTr').hide();
		$('#modelcodeTr').show();
		$('#protocolTr').show();
		$('#confTr').show();
		$('#addr1').val("");
		$('#addr2').val("");
		$('#addr1Tr').show();
		$('#addr1Name').html("额外地址1");
		$('#addr2Tr').show();
		$('#addr2Name').html("额外地址2");
	}
	var currconf = $("#conf").val();
	if(currconf == '02'){
		$('#modelcode').val('00');
		$('#protocol').val('00');
		$('#modelcodeTr').hide();
		$('#protocolTr').hide();
	}
	/*if(etype == '14')//彩灯
	{
		$('#shapeTr').show();
		$('#countTr').show();
		FillSelectSetCurVal(shapeTypeMap,'shape','1');	
		
		$('#dirTr').hide();
		$('#distribTr').hide();
	}*/
	
});
$('#shape').change(function(e){
	e.preventDefault();
	var shape=$("#shape").children("option:selected").val();
	if(shape == '3'){
		$('#dirTr').show();
		$('#distribTr').show();
		$('#distrib1').attr("validate","required");
		$('#distrib2').attr("validate","required");
		$('#distrib3').attr("validate","required");
		$('#distrib4').attr("validate","required");
		FillSelectSetCurVal(dirTypeMap,'dir','1');
	}
	else{
		$('#distrib1').removeAttr("validate");
		$('#distrib2').removeAttr("validate");
		$('#distrib3').removeAttr("validate");
		$('#distrib4').removeAttr("validate");
		$('#dirTr').hide();
		$('#distribTr').hide();
	}
});
$('#conf').change(function(e){
	e.preventDefault();
	var currconf = $( '#conf' ).val();
	if(currconf == '02'){
		$('#modelcode').val('00');
		$('#protocol').val('00');
		$('#modelcodeTr').hide();
		$('#protocolTr').hide();
	}else{
		$('#modelcodeTr').show();
		$('#protocolTr').show();
	}
});
 $('#ctrltype').change(function(e){
	e.preventDefault();
	var currctype = parseInt($( '#ctrltype' ).val());
	$("#epAddModaltable #dchanTr td").remove();
	var TextTd = "<td>设备通道</td><td><input type='text' name='dchan' id='dchan' validate='required|integer' class='input-xlarge'></td>";
	var SelectTd = "<td>设备通道</td><td><select  name='dchan' id='dchan' class='input-xlarge' validate='required' ></select></td>";
	if(currctype == 1 ){
		FillSelect(LONinterfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","LON");
		$("#epAddModaltable #dchanTr").append(TextTd);
		$("#epAddModaltable #dchan").attr("placeholder","输入0~127");
		$('#epAddModaltable #dchan').removeAttr("validate");
		$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
		$('#dtypeTr').show();
	}
	else if(currctype == 2 ){
		FillSelect(l880interfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","L880");
		$("#epAddModaltable #dchanTr").append(SelectTd);
		InitDchanSelecthtml(GetCurrl880interfaceRangeData(1),'dchan');
		
		$('#dtypeTr').show();
	}
	else if(currctype == 4 ){
		FillSelect(NICODMX512interfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","NICODMX512");
		
		$("#epAddModaltable #dchanTr").append(TextTd);
		$('#epAddModaltable #dchan').val("0");
		$('#epAddModaltable #dchan').attr("readOnly","true");
		$('#dtypeTr').show();
	}
	else if(currctype == 5 ){
		FillSelect(l830linterfaceTypeMap,'devtype');
		$("#epAddModaltable #devtype").attr("interfaceType","L830L");
		$("#epAddModaltable #dchanTr").append(SelectTd);
		InitDchanSelecthtml(GetCurrl830linterfaceRangeData(1),'dchan');
		
		$('#dtypeTr').show();
	}
	else{
		$('#dtypeTr').hide();
		$("#epAddModaltable #dchanTr").append(TextTd);
	}
});
$('#devtype').change(function(e){
	e.preventDefault();
	var type = $("#devtype").attr("interfaceType");
	var value = parseInt($("#devtype").val());
	$("#epAddModaltable #dchanTr td").remove();
	var TextTd = "<td>设备通道</td><td><input type='text' name='dchan' id='dchan' validate='required|integer' class='input-xlarge'></td>";
	var SelectTd = "<td>设备通道</td><td><select  name='dchan' id='dchan' class='input-xlarge' validate='required' ></select></td>";
	if(type == 'LON'){
		$("#epAddModaltable #dchanTr").append(TextTd);
		switch(value){
			case 1:
			case 2:
			case 3:
				
				$("#epAddModaltable #dchan").attr("placeholder","输入0~127");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
				break;
			case 4:
				
				$("#epAddModaltable #dchan").attr("placeholder","输入0~26");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[27]");
				break;
			case 5:
			case 6:
			case 7:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~15");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[16]");
				break;
			case 8:
			case 9:
			case 10:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~31");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[32]");
				break;						
			default:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~127");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[128]");
				
		}
	}
	if(type == 'L880'){
		
		if(value == 4 || value == 5){
			$("#epAddModaltable #dchanTr").append(TextTd);

			$('#epAddModaltable #dchan').val("0");
			$('#epAddModaltable #dchan').attr("readOnly","true");
		}
		else{
			$("#epAddModaltable #dchanTr").append(SelectTd);
			InitDchanSelecthtml(GetCurrl880interfaceRangeData(value),'dchan');
			
		}
		
	}
	if(type == 'NICODMX512'){
		if(value == 1){
			$("#epAddModaltable #dchanTr").append(TextTd);
			$('#epAddModaltable #dchan').val("0");
			$('#epAddModaltable #dchan').attr("readOnly","true");
			/*var checkStr = $('#epAddModaltable #model').val().substring(0,4);
			if(checkStr == '0x0102'){
				
			}*/
		}else{
			$("#epAddModaltable #dchanTr").append(SelectTd);
			InitDchanSelecthtml(GetCurrNICODMX512interfaceRangeData(value),'dchan');
		}
		/*switch(value){
			
			case 1:
			case 3:
			case 4:
			case 5:
			case 6:
				$('#epAddModaltable #dchan').val("0");
				$('#epAddModaltable #dchan').attr("readOnly","true");
				break;
			case 2:
				$("#epAddModaltable #dchan").attr("placeholder","输入0~255");
				$('#epAddModaltable #dchan').removeAttr("validate");
				$("#epAddModaltable #dchan").attr("validate","required|integer|less_than[256]");
				break;
			default:
				$('#epAddModaltable #dchan').val("0");
				$('#epAddModaltable #dchan').attr("readOnly","true");
				
		}*/
	}
	if(type == 'L830L'){		
		
			$("#epAddModaltable #dchanTr").append(SelectTd);
			InitDchanSelecthtml(GetCurrl830linterfaceRangeData(value),'dchan');
			
		
	}
	/*if(value == 1){
		var ctrlid = $('#ctrlid').val();
		if(ctrlid == '3'){
			$("#addr1").attr("placeholder","输入ip");
			$("#addr1").attr("placeholder","输入ip");
		}
	}*/
});
$('#SelectFloor').change(function(e){
	e.preventDefault();
	currfloorid = $( '#SelectFloor' ).val();
	LoadAreaType(GetCurrFloorAreaData(currfloorid));
	
});
$('#areaAddselect').change(function(e){
	e.preventDefault();
	$('#areaAddname').removeClass("error");
	$('#areaAddModal .text-error').remove();
	$('#areaAddname').val($('#areaAddselect').find("option:selected").text());
});
$('#subaddbtn').click(function (e) {
	 e.preventDefault();
	 $('#epAddModal').modal('show');
	 $('#floorid').val(currfloorid);
	                
 });
 $('#areabtnAdd').click(function (e) {
	 e.preventDefault();
	 $("#areaAddModalLabel").text("添区域信息");
	 $("#areaAddname").val("");
	 $("#areaAddModal_addbtn").attr("onclick","areaAddModal_add_action()");
	 $("#areaAddModal_addbtn").text("添加");
	 $('#areaAddselect').removeClass("error");
	 $('#areaAddModal .text-error').remove();
	 $('#areaAddModal').modal('show');   
	 var optionObj = $("#areaAddselect > option");
	 $.each(optionObj,function(index,item){
		if($(item).attr("selected") == "selected"){
			$(item).attr("selected",false);
		}
	 });
	 $("#areaAddselect   option[value='1']").attr("selected","selected");
	 
 });
 
  $('#areabtnEdit').click(function (e) {
	 e.preventDefault();
	 $("#areaAddModalLabel").text("修改区域信息");
	 $("#areaAddModal_addbtn").attr("onclick","areaAddModal_Edit_action()");
	  $("#areaAddModal_addbtn").text("确定");
	 $('#areaAddselect').removeClass("error");
	 $('#areaAddModal .text-error').remove();
	 var CurAreaName = $("#myTab").find(".active").children("a").text();
	 var CurAreaAtype = getCurAreaAtype(CurAreaName);
	 $("#areaAddselect" + " option[value='" + CurAreaAtype + "']").attr("selected", "selected");
	 $("#areaAddname").empty();
	 $("#areaAddname").val(CurAreaName);
	 $('#areaAddModal').modal('show');       
        
 });
 
 $('#areabtnDel').click(function (e) {
	 e.preventDefault();
	 
	 var currFloorid = $( '#SelectFloor' ).val();
	InitareaSelecthtml(GetCurrFloorAreaData(currFloorid),'areaDelselect');
	 $('#areaDelModal').modal('show');               
 });
 
 $('#flooraddbtn').click(function (e) {
	 e.preventDefault();
	 $("#floorAddModalLabel").text("添加楼层信息");
	 $("#addfloorname").empty();
	 //if ($('#addfloorid').hasClass("error")) {
	  	$('#addfloorid').removeClass("error");
		$('#addfloorname').removeClass("error");
		$('#floorAddModal .text-error').remove();
	  //}
	  $("#floorAddModal_addbtn").text("添加");
	  $("#floorAddModal_addbtn").attr("onclick","floor_add_action()");
	  $('#addfloorid').val(GetAutoFloorid());
	  $('#addfloorid').attr("readonly","readonly");
	  $('#addfloorname').val("");
	 $('#floorAddModal').modal('show');               
 });
 
  $('#flooreditbtn').click(function (e) {
	 e.preventDefault();
	 $("#floorAddModalLabel").text("修改楼层信息");
	 //if ($('#addfloorid').hasClass("error")) {
	 var CurFloorName = $("#SelectFloor").children("option:selected").text();
	 $("#floorAddModal_addbtn").text("确定");
	 $("#floorAddModal_addbtn").attr("onclick","floor_edit_action()");
	 $('#addfloorid').removeClass("error");
	 $('#addfloorname').removeClass("error");
	 $('#floorAddModal .text-error').remove();
	  //}
	  $('#addfloorid').val(GetAutoFloorid());
	  $('#addfloorid').attr("readonly","readonly");
	  $("#addfloorname").val(CurFloorName);
	 $('#floorAddModal').modal('show');               
 });
 
 $('#floordelbtn').click(function (e) {
	 e.preventDefault();
	 
	 $('#floorDelModal').modal('show');               
 });
 
 $('#areaDelModal_delbtn').click(function (e) {
	 e.preventDefault();
	 var currDelAreaid = $( '#areaDelselect' ).val();
	 if(DelAreaidAction(currDelAreaid)){
	 	currfloorid = $( '#SelectFloor' ).val();
		LoadAreaType(GetCurrFloorAreaData(currfloorid));
		$('#ScenesListTable').bootstrapTable('load',{data:CurrScenesArry});
		$('#areaDelModal').modal('hide');
	 }
 });
 $('#floorDelModal_delbtn').click(function (e) {
	 e.preventDefault();
	 var currDelfloorid = $( '#SelectFloor' ).val();
	 if(DelFloorAction(currDelfloorid)){
	 	currfloorid = "undefind";
		InitFloorSelecthtml(CurrFloorArry,'SelectFloor');
		currfloorid = $( '#SelectFloor' ).val();
		LoadAreaType(GetCurrFloorAreaData(currfloorid));
		$('#ScenesListTable').bootstrapTable('load',{data:CurrScenesArry});
		$('#floorDelModal').modal('hide');
	 }
 });

 $('#cmdctype').change(function(e){
	e.preventDefault();
	$('#CMDAddModal .text-error').remove();
	var curcmdctype = $( '#cmdctype' ).val();
	var curoemid = $('#oemId').val();
	if(curcmdctype == '0')
	{
	    //$.each(CurrElemArry,function(index,item) {
			//if (nowepid == item.epid) {
				//$('#CMDAddtable #oidSelect').show();
		        //$('#CMDAddtable #oid').hide();
			//}
		//});
	    //$('#CMDAddtable #oidSelect').val($('#CMDAddtable #oid').val());		
		InitMCMDForm('2');
	}
	else{
	    //$('#CMDAddtable #oidSelect').hide();
		//$('#CMDAddtable #oid').show();
		$('#cmddtype').empty();
		if(GetCurrcTypeOemIdModelData(curcmdctype,curoemid)){
			FillNoChoosedSelect(cmdOemIdModelMap,'cmddtype');
			$('#cmddtype').val('00');
			$("#cmddtype option[value='00']").attr("selected","selected");
			$("#cmddtypeTR").show();
			var cmddata = GetCurrcmdTypeMCMDData(curcmdctype, curoemid, '00');		
			if(cmddata != false)
				$.fn.tables.bindObjData('MCMDtable', eval(cmddata));
			else
				InitMCMDForm('2');
		}else{
			var errorMsg = "该厂商型号目前不存在模板命令";
			$('#cmdctype').after("<span class='text-error'>" + errorMsg + "</span>");
			$("#cmddtypeTR").hide();
			
			InitMCMDForm('2');
		}	
	}	
	
});
$('#cmddtype').change(function(e){
	e.preventDefault();
	$('#CMDAddModal .text-error').remove();
	var curcmdctype = $( '#cmdctype' ).val();
	var curoemid = $('#oemId').val();
	var curmodel = $('#cmddtype').val();
	var cmddata = GetCurrcmdTypeMCMDData(curcmdctype, curoemid, curmodel);		
	if(cmddata != false)
		$.fn.tables.bindObjData('MCMDtable', eval(cmddata));
	else
		InitMCMDForm('2');
});
 $('#SenceGroup_addbtn').click(function (e) {
	 e.preventDefault();
	  InitFloorSelecthtml(CurrFloorArry,'scenFloorid');
	  var currscenFloorid = $( '#scenFloorid' ).val();
	  InitareaSelecthtml(GetCurrFloorAreaData(currscenFloorid),'scenAreaid');
	  $("#SceneGroupAddModal_addbtn").attr("onclick","AddSceneGroupAction();");
	  $("#SceneGroupListtable").find("tbody").find("tr").remove();
	  $('#SceneGroupAddModal .input-xlarge').removeClass("error");
	  $('#SceneGroupAddModal .text-error').remove();
	  $('#SceneGroupAddModal').modal('show');               
 });
 $('#SenceGroup_Delbtn').click(function (e) {
	 e.preventDefault();
	 var currDelIds = "";
		var rows = $('#ScenesListTable').bootstrapTable('getSelections');
		for (var i = 0; i < rows.length; i++) {
			
			currDelIds += rows[i].id + ',';
		}
		currDelIds = currDelIds.substring(0, currDelIds.length - 1);
		if (currDelIds == "" || currDelIds.length == 0) {
		alert("请选择您要删除的记录！");
		return;
		}	
		$('#DeleteAllModal').addClass('modalSence');
		$('#DeleteAllModal').modal('show');	
		$("#DeleteAllModal_delbtn").attr("onclick","DelScesetAction('"+currDelIds+"');");              
 });
 
 $('#scenFloorid').change(function(e){
	e.preventDefault();
	var currscenFloorid = $( '#scenFloorid' ).val();
	InitareaSelecthtml(GetCurrFloorAreaData(currscenFloorid),'scenAreaid');
	
});
 $('#savecfgbtn').click(function (e) {
	 e.preventDefault();
	 /********联动配置界面当触发设备为场景时oid置0，这里为了将版本更新前的脏数据改正********/
	 $.each(CurrElemArry,function(index,elem){				
		 if (elem.etype == "01"){
		     $.each(CurrElemTriggerArry,function(indexTri,elemTri){
		         if (elemTri.t_epid == elem.epid) {
		         	 
		             elemTri.oid = 0;
		         }
		     });
		 }
	 });
	 /**end**/
	 SaveCfgAction(currusername);
});

//应用配置
 $('#applycfgbtn').click(function (e) {
	 e.preventDefault();
	 $.ajax({ 
		url : '../orgMgr/devCfg/applyConf',  
		type: 'GET',  
		dataType: 'json',  
		timeout: 10000,  
		cache: false,
		data:{"dnid": currusername},
		error : function() {
				 alert("获取数据异常，请重新获取"); 
				},   
		success:function(data){
				bootbox.alert(data.resultMsg, function() {					
					return;
				});		
			
		} 
	});
});
 /*枫叶报警器配置处理*/
$('#Selectalarm').change(function(e){
	e.preventDefault();
	curralarmid = $("#Selectalarm").val();
	LoadAlarmsIdSelect(curralarmid);
	
	$('#AlarmAreaListTable').bootstrapTable('load',{data:GetCurrAlarmAreaData(curralarmid)});
});
/**************自动生成楼层id*****************/ 
function GetAutoFloorid() {
    var id=1;
    while (1) {   
        if (!IsExistId(id)) {
            return id;
        }
        id++;
    }   
}
function IsExistId(currid) {
    var isExist = false;
    $.each(CurrFloorArry,function(index,elem){		
		if (elem.id == currid) {
		    isExist = true;
		}
    });
    return isExist;
}

/**************子场景选项为其他的时候显示输入框************/
 $('#sceneType').change(function(e){
	e.preventDefault();
	var sceneTypeid = $('#sceneType').val();
	if (sceneTypeid != '999') {
		$('#OtherSceneTypeView').hide();
	}
	else {
		$('#sceneTypeName').val('');
	    $('#OtherSceneTypeView').show();
	}	
});
$('#AlarmArea_addbtn').click(function (e) {
	 e.preventDefault();
	 AlarmAreaidint ++;
	 $('#AlarmAreaAddtable #id').val(AlarmAreaidint);
	 $('#AlarmAreaAddModal .input-small').removeClass("error");
	 $('#AlarmAreaAddModal .text-error').remove();
	 $('#AlarmAreaAddModal').modal('show'); 
});
$('#AlarmArea_Delbtn').click(function (e) {
	 e.preventDefault();
	 var currDelIds = "";
		var rows = $('#AlarmAreaListTable').bootstrapTable('getSelections');
		for (var i = 0; i < rows.length; i++) {
			
			currDelIds += rows[i].id + ',';
		}
		currDelIds = currDelIds.substring(0, currDelIds.length - 1);
		if (currDelIds == "" || currDelIds.length == 0) {
		alert("请选择您要删除的记录！");
		return;
		}	
		$('#DeleteAllModal').addClass('modalAlarm');
		$('#DeleteAllModal').modal('show');	
		$("#DeleteAllModal_delbtn").attr("onclick","DelAlarmAreaAction('"+currDelIds+"');");   
});
});

/*修改楼层名称动作*/
function floor_edit_action(){
	 //e.preventDefault(); 
	 //var fid = $('#addfloorid').val();
	 var fname = $('#addfloorname').val();
	 var CurFloorName = $("#SelectFloor").children("option:selected").text();
	 var  integerRegex = /^\-?[0-9]+$/;
	 var ispass = validateRow('floorAddTable');
		if(!ispass){
			
			return false;
	}
	 var isAlreadyid = false;
	 if(CurrFloorArry.length != 0){
	 	var Curid = [];	
		Curid = $.grep(CurrFloorArry,function(item, index){
		},false);
	 	if(Curid.length != 0)
			isAlreadyid = true;	 	
	 }
	 if(isAlreadyid == true)
	 {
	 	var errorMsg = "该楼层ID已经存在";
		$('#addfloorid').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
	 	return false;
	 }	 
	 else{
	 	 var isAlreadyname = false;
		 if(CurrFloorArry.length != 0){
			
			var Curname = [];
			Curname = $.grep(CurrFloorArry,function(item, index){
														   
				if(item.name == fname)
					return true;
			},false);
			if(Curname.length != 0)
				isAlreadyname = true;	 	
		 }
		 if(isAlreadyname == true)
		 {
			var errorMsg = "该楼层名称已经存在";
			$('#addfloorname').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
			return false;
		 }
		 else{	 
			 //CurrFloorArry.push({ "id": fid, "name": fname });
			 var fid ='';
			 $.each(CurrFloorArry,function(index,item){
				//CurFloorName
				if(item.name == CurFloorName){
					item.name = fname;
					fid = item.id;
				}
			 })
			  $.unique(CurrFloorArry);
			  CurrfloorMap.put(fid,fname);
			 InitFloorSelecthtml(CurrFloorArry,'SelectFloor');
			 currfloorid = $("#SelectFloor").val();
			 $('#floorAddModal').modal('hide');
		 }
	 }               
 }
/*添加楼层动作*/
 function floor_add_action(){
	 //e.preventDefault(); 
	 
	 var fid = $('#addfloorid').val();
	 var fname = $('#addfloorname').val();
	 var  integerRegex = /^\-?[0-9]+$/;
	 if(!integerRegex.test(fid))
	 {
		 
		 $('#addfloorid').addClass('error').after("<span class='text-error'>此字段必须为整数</span>");
		return;
	 }
	 var ispass = validateRow('floorAddTable');
		if(!ispass){
			
			return false;
	}
	 var isAlreadyid = false;
	 if(CurrFloorArry.length != 0){
	 	var Curid = [];
		
		Curid = $.grep(CurrFloorArry,function(item, index){
													   
			if(item.id == fid)
				return true;
		},false);
	 	if(Curid.length != 0)
			isAlreadyid = true;	 	
	 }
	 if(isAlreadyid == true)
	 {
	 	var errorMsg = "该楼层ID已经存在";
		$('#addfloorid').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
	 	return false;
	 }	 
	 else{
	 	 var isAlreadyname = false;
		 if(CurrFloorArry.length != 0){
			
			var Curname = [];
			Curname = $.grep(CurrFloorArry,function(item, index){
														   
				if(item.name == fname)
					return true;
			},false);
			if(Curname.length != 0)
				isAlreadyname = true;	 	
		 }
		 if(isAlreadyname == true)
		 {
			var errorMsg = "该楼层名称已经存在";
			$('#addfloorname').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
			return false;
		 }
		 else{	 
			 //addfloorDataToArry(addfloor, fid, fname);
			 //CurrFloorArry = $.merge(CurrFloorArry,addfloor);
			 CurrFloorArry.push({ "id": fid, "name": fname });
			  $.unique(CurrFloorArry);
			  CurrfloorMap.put(fid,fname);
			 InitFloorSelecthtml(CurrFloorArry,'SelectFloor');
			 currfloorid = $("#SelectFloor").val();
			 $('#floorAddModal').modal('hide');
		 }
	 }               
 }
 
 /*修改区域名称区域动作*/
 function areaAddModal_Edit_action(e) {
	 //e.preventDefault();
	 var CurAreaName = $("#myTab").find(".active").children("a").text();
	 var CurAreaAtype = $("#areaAddselect").children("option:selected").val();
	 var aid = $('#areaAddselect').val();
	 var aname = $('#areaAddname').val();
	 currfloorid = $( '#SelectFloor' ).val();
	 if(aname == "")
	 {
	 	var errorMsg = "请输入区域名称";
		$('#areaAddname').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
	 	return false;
	 }
	 var isAlready = false;
	 if(CurrAreaArry.length != 0){
	 	var Cur = [];
		Cur = $.grep(CurrAreaArry,function(item, index){										   
			if(item.floorid == currfloorid && item.name == aname)
				return true;
		},false);
	 	if(Cur.length != 0)
			isAlready = true;
	 }
	 if(isAlready == true)
	 {
	 	var errorMsg = "该楼层已经存在该区域";
		$('#areaAddname').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
	 	return false;
	 }else{
	
		 //areaidint ++;
		 //parseInt(areaidint);
		 //CurrAreaArry.push({ "floorid": currfloorid, "id": areaidint, "atype": aid, "name": aname });
		 var aid='';
		 $.each(CurrAreaArry,function(index,item){
		 	if(item.name == CurAreaName){
		 		item.name = aname;
				aid = item.id;
				//item.atype = CurAreaAtype;
		 	}
		 });
		 $.unique(CurrAreaArry);
		 CurrAreaNameMap.put(aid,aname);
		 CurrAreaArry = CurrAreaArry.sort(function(a, b){  //按id排序
                    		return (a.id - b.id);
                		});
		 $('#areaAddModal').modal('hide'); 
		var currfid = 'floor' + currfloorid;
		$('.well').attr("id",currfid);
		LoadNavtabs(GetCurrFloorAreaData(currfloorid));
		//$("#myTab").find(".active").removeClass("active");
		var AObj = $("#myTab > li > a");
		$.each(AObj,function(index,item){
			var name = $(item).text()
			if(name==aname){
				$(item).click();
				return;
			}
		});	 
	}              
 }
 /*添加区域动作*/
function areaAddModal_add_action() {
	 //e.preventDefault();
	 var aid = $('#areaAddselect').val();
	 //var aname = $('#areaAddselect').find("option:selected").text();
	 var aname = $('#areaAddname').val();
	 currfloorid = $( '#SelectFloor' ).val();
	 if(aname == "")
	 {
	 	var errorMsg = "请输入区域名称";
		$('#areaAddname').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
	 	return false;
	 }
	 var isAlready = false;
	 if(CurrAreaArry.length != 0){
	 	var Cur = [];
		Cur = $.grep(CurrAreaArry,function(item, index){
													   
			if(item.floorid == currfloorid && item.name == aname)
				return true;
		},false);
	 	if(Cur.length != 0)
			isAlready = true;
	 }
	 if(isAlready == true)
	 {
	 	var errorMsg = "该楼层已经存在该区域";
		$('#areaAddname').addClass('error').after("<span class='text-error'>" + errorMsg + "</span>");
	 	return false;
	 }else{	
		 areaidint ++;
		 parseInt(areaidint);
		 CurrAreaArry.push({ "floorid": currfloorid, "id": areaidint, "atype": aid, "name": aname });
		 $.unique(CurrAreaArry);
		 CurrAreaNameMap.put(areaidint,aname);
		 $('#areaAddModal').modal('hide'); 
		var currfid = 'floor' + currfloorid;
		$('.well').attr("id",currfid);
		LoadNavtabs(GetCurrFloorAreaData(currfloorid));	 
	}               
 }
 function getCurAreaAtype(CurAreaName){
	var CurAreaAtype='';
	$.each(CurrAreaArry,function(index,item){
		if(item.name == CurAreaName){
		 	CurAreaAtype = item.atype;
		 }
	});
	return CurAreaAtype;
 }
</script>

  </head>

 
  <body> 
  <!--<![endif]-->
<!-- main container -->
    <div class="content">       
        <div class="container-fluid">
         <div id="pad-wrapper"  style="margin-top:15px;" class="users-list">
		<div >
							<div class="alert alert-info hidden-tablet">
                            <div><i  style="top:0;" class="icon-lightbulb pull-left"></i>
                            该配置页面的所有配置内容需要您在配置完成后点击下方的 <i style='color:red'>“保存配置”</i> 按钮方可生效！请勿在未保存的情况下离开该页面。
                            </div>
                            <div>
                        	<i  style="top:0;" class="icon-lightbulb pull-left"></i>
                            该配置页面的所有配置内容在您点击下方的“保存配置”按钮后，再点击 <i style='color:red'>“应用配置”</i> 按钮，让设备的配置及时生效！
                            </div>
                        	</div>
		</div>
		<div class="row-fluid header">
                    <h3>配置管理&nbsp;&nbsp;&nbsp;</h3><h4  style="margin-left:0; margin-top:3px;" id="currRouterid"></h4>
                    <div class="pull-right"> 
                    <a    id="savecfgbtn" class="btn btn-danger">保存配置</a>
					<a    id="applycfgbtn" class="btn btn-danger">应用配置</a>
                    </div>
					
                    <div class="span10 pull-right" id="div_find">
                        <input type="text" class="span5 search" id="Dtext" placeholder="Type a user's name..." />
                        
                       
                        <div class="ui-dropdown">
                            <div class="head" data-toggle="tooltip" title="Click me!" id="search_btn">
                                设备筛选
                                
                            </div>  
                            
                               
                        </div>
						
						
                    </div>
					 
                    
                </div>

<div id="cfgShow">
<div class="row-fluid chart" id="router">
                    <div class="row-fluid head">
                        <div class="span12">
							<h4 style="margin-left:10px;margin-bottom:5px;">楼层配置&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn-flat" id="flooraddbtn"><i class="icon-plus"></i>添加</button>&nbsp;&nbsp;<button class="btn-flat success" id="flooreditbtn"><i class="icon-edit"></i>编辑</button>&nbsp;&nbsp;<button class="btn-flat danger" id="floordelbtn"><i class="icon-remove"></i>删除</button></h4><br>
                            <h4 style="margin-left:10px;">选择楼层 <small><select id="SelectFloor">	</select></small>&nbsp;&nbsp;<!--<a   style="margin-top:-8px;" id="flooraddbtn" class="btn-flat"><span>&#43;</span>添加楼层</a>--></h4>
                        </div>
                    </div>
					<div id='value'>
                           
                        </div>
</div>
<div class="table-wrapper table-products section">
	<h4 style="margin-left:10px;margin-bottom:15px;">区域配置&nbsp;&nbsp;&nbsp;&nbsp;<button class="btn-flat" id="areabtnAdd"><i class="icon-plus"></i>添加</button>&nbsp;&nbsp;<button  class='btn-flat success'  id='areabtnEdit'><i class='icon-edit'></i>编辑</button>&nbsp;&nbsp;<button  class='btn-flat danger'  id='areabtnDel'><i class='icon-remove'></i>删除</button></h4>
	<div class="well area"  style="margin-top:5px; background-color:#ffff; border:#ffff;" id="floor1" >	   
		<ul class="nav nav-tabs" id="myTab" style=" border-bottom:#ffff">
			
			<!--<li><button class="btn-flat" data-toggle='modal' data-target='#areaAddModal' id="areabtnAdd"><i class="icon-plus"></i>添加区域</button>&nbsp;&nbsp;<button  class='btn-flat danger pull-right' data-toggle='modal' data-target='#areaDelModal' id='areabtnDel'><i class='icon-remove'></i>删除区域</button></li>-->
		
		</ul>
		<div id="myTabContent" class="tab-content section">
				
			
		</div>
	</div>
</div>
<div class="table-wrapper table-products section">
<h4 style="margin-left:10px;margin-bottom:5px;">自定义场景配置</h4>
	
					<div id="myScenceTabContent" class="tab-content section">								
							<div class="row-fluid tab-pane fade in active" >
								 <form >
								 <div>
									 <h4 style="margin-left:10px;margin-bottom:15px;">场景组列表&nbsp;&nbsp;&nbsp;&nbsp;
									 <button  class="btn-flat" id='SenceGroup_addbtn'><i class="icon-plus"></i>添加</button>
									 &nbsp;&nbsp;&nbsp;&nbsp;<button  class="btn-flat danger" id="SenceGroup_Delbtn"><i class="icon-remove"></i>删除</button>
									 &nbsp;&nbsp;</h4>
								 </div>
								 <div>
									<table id='ScenesListTable'></table>
								 </div>
								 </form>
				 			</div>
					</div>
	

</div>
<div class="table-wrapper table-products section">
	<h4 style="margin-left:10px;margin-bottom:5px;">报警主机配置</h4>
	<h4 style="margin-left:10px;">选择报警主机
	<small><select id="Selectalarm">
	<option value="1" selected="selected">一楼</option>
	</select>
	</small>&nbsp;&nbsp;
	</h4>	
	<div id="alarmTabContent" class="tab-content section">								
			<div class="row-fluid tab-pane fade in active" >
				 <form >
				 <div>
					 <h4 style="margin-left:10px;margin-bottom:15px;">报警主机分区组列表&nbsp;&nbsp;&nbsp;&nbsp;
					 <button  class="btn-flat" id='AlarmArea_addbtn'><i class="icon-plus"></i>添加</button>
					 &nbsp;&nbsp;&nbsp;&nbsp;<button  class="btn-flat danger" id="AlarmArea_Delbtn"><i class="icon-remove"></i>删除</button>	&nbsp;&nbsp;</h4>
				 </div> 
				 <div id="AlarmAreaListDiv">
					<table id='AlarmAreaListTable'></table>
				 </div>
				 </form>
			</div>
	</div>
	

</div>


	
            </div>
        </div>
    </div>   
<div class="modal small hide fade" id="floorAddModal" tabindex="-1" role="dialog" aria-labelledby="floorAddModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="floorAddModalLabel">添加楼层信息</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="floorAddModalform">
					<!--<select id="floorAddselect">
					</select>-->
					<table id="floorAddTable">						
						<tr hidden="hidden"><td>楼层ID</td><td id="addflooridtd"><input type="text" id="addfloorid" name="addfloorid"  validate="required|integer" class="input-xlarge" ></td></tr>
						<tr><td>楼层名称</td><td><input type="text" id="addfloorname"  name="addfloorname"  validate="required|max_length[24]" class="input-xlarge" ></td></tr>						
					</table>					
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger"  id="floorAddModal_addbtn">添加</button>
				</div>
</div> 
<div class="modal small hide fade" id="floorDelModal" tabindex="-1" role="dialog" aria-labelledby="floorDelModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 >删除楼层信息</h3>
				</div>
				<div class="modal-body">
					
					<h4 style="color:#C22CA3;" class="error-text"><i class="icon-warning-sign modal-icon"></i>删除楼层信息的同时，该楼层下相关的所有区域信息，设备信息，命令信息，联动信息，场景信息均被删除！请谨慎！是否确认删除？</h4>
					
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger"  id="floorDelModal_delbtn">删除</button>
				</div>
</div> 
<div class="modal small hide fade" id="areaAddModal" tabindex="-1" role="dialog" aria-labelledby="areaAddModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="areaAddModalLabel">添加区域信息</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="areaAddModalform">
					<table>
						<tr><td>区域图标:</td><td id="areaAddselecttd"> <select id="areaAddselect" validate="required" class="input-xlarge"></select></td></tr>
						<tr><td>区域名称:</td><td > <input type="text" id="areaAddname"  name="areaAddname"  validate="required|max_length[24]" class="input-xlarge" ></td></tr>
					</table>													
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" id="areaAddModal_addbtn">添加</button>
				</div>
</div> 
<div class="modal small hide fade" id="areaDelModal" tabindex="-1" role="dialog" aria-labelledby="areaDelModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 >删除区域信息</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="areaAddModalform">
					<h4 style="float:left;margin-bottom:10px; color:#C22CA3;"><i class="icon-warning-sign modal-icon"></i>删除区域的同时，该区域下相关的所有设备信息，命令信息，联动信息，场景信息均被删除！请谨慎！</h4><br>
					<table>
						<tr><td>选择要删除的区域:</td><td > <select id="areaDelselect"  name="areaDelselect" class="input-xlarge"></select></td></tr>
						
					</table>													
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" id="areaDelModal_delbtn">删除</button>
				</div>
</div> 
<div class="modal small hide fade" id="epAddModal" tabindex="-1" role="dialog" aria-labelledby="epAddModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="epAddModalLabelTitle">添加设备信息</h3>
				</div>
				<div class="modal-body">
					<div class="form-group form-item addepdiv" align="center">
         			<form id="epAddModalform"  name="epAddModalform" >
					<table id="epAddModaltable">
						<tr style="display:none"><td>楼层</td><td><input type="text" name='floorname' id="floorname"   class="input-xlarge" ></td></tr>
						<tr style="display:none"><td>楼层名称</td><td><input type="text" name='floorid' id="floorid"   class="input-xlarge" ></td></tr>
						<tr style="display:none"><td>区域</td><td><input type="text" name='atypename' id="atypename"  class="input-xlarge" ></td></tr>						
						<tr style="display:none"><td>区域名称</td><td><input type="text" name='atype' id="atype"  class="input-xlarge" ></td></tr>
						<tr style="display:none"><td>epid</td><td><input  type="text" name='epid' id="epid"   class="input-xlarge"></td></tr>
						
						<tr><td>设备类型</td><td><select  style="width:270px;" name='etype' id="etype" validate="required" class="input-xlarge"></select></td></tr>
						<tr ><td>设备名称</td><td><input type="text" name='etypename' id="etypename"  validate="required|max_length[64]" class="input-xlarge" value="场景" ></td></tr>
						<tr  id="devModelTr"><td>模板选择</td><td><select name='modelselect' id="modelselect" class="input-xlarge" ></select></td></tr>			
						<tr><td>控制器类型</td><td><select name='ctrltype' id="ctrltype" class="input-xlarge"></select></td></tr>
						<tr style="display:none"><td>控制器类型名称</td><td><input type="text" name='ctypename' id="ctypename"   class="input-xlarge" ></td></tr>
						<tr style="display:none"><td>控制器通道</td><td><input type="text" name='ctrlid' id="ctrlid"  value="1" validate="required|integer" class="input-xlarge"></td></tr>
						<tr id='dtypeTr' ><td>接口类型</td><td><select name='devtype' id="devtype" class="input-xlarge"></select></td></tr>
						<tr style="display:none"><td>接口类型名称</td><td><input type="text" name='dtypename' id="dtypename"   class="input-xlarge" ></td></tr>
						
							
						<tr id="dchanTr"><td>设备通道</td><td><input type="text" name='dchan' id="dchan" validate="required|integer" class="input-xlarge"></td></tr>
						<tr  id="confTr"><td>协议类型</td><td><select name='conf' id="conf" class="input-xlarge" validate="required" ></select></td></tr>
						<tr   id="modelcodeTr" ><td>厂家编号</td><td><input type="text" name='modelcode' id="modelcode" class="input-xlarge" validate="isHex|Lengthequal[2]"></td></tr>
						<tr  id="protocolTr" ><td>协议编号</td><td><input type="text" name='protocol' id="protocol" class="input-xlarge" validate="isHex|Lengthequal[2]"></td></tr>
						<tr style="display:none"><td>厂商型号</td><td><input name='model' id="model" class="input-xlarge" validate="required"></td></tr>
						<!--<tr style="display:none"><td>厂商型号名称</td><td><input type="text" name='modelname' id="modelname" class="input-xlarge"></td></tr>	-->
						<tr id="shapeTr" style="display:none"><td>彩灯形状</td>
						<td>
						<select name='shape' id="shape" class="input-xlarge" >
						<option value="1">直线</option>
						<option value="2">圆</option>
						<option value="3">矩形</option>
						</select>
						</td>
						</tr>
						<tr id="countTr" style="display:none"><td>彩灯总节数</td><td><input type="text" name='count' id="count"   class="input-xlarge" ></td></tr>	
						<tr id="dirTr" style="display:none"><td>布线方向</td>
						<td>
						<select name='dir' id="dir" class="input-xlarge"  >
						<option value="0">请选择</option>
						<option value="1">顺时针</option>
						<option value="2">逆时针</option>						
						</select>
						</td>
						</tr>
						<tr id="distribTr" style="display:none"><td>矩形四边分布灯数</td><td>边一<input type="text" name='distrib1' id="distrib1" class="input-xlarge" validate="required" style="width:15%">边二<input type="text" name='distrib2' id="distrib2" class="input-xlarge" validate="required" style="width:15%"><br>边三<input type="text" name='distrib3' id="distrib3" class="input-xlarge" validate="required" style="width:15%">边四<input type="text" name='distrib4' id="distrib4" class="input-xlarge" validate="required" style="width:15%"></td></tr>
						<tr style="display:none"><td>distrib</td><td><input type="text" name='distrib' id="distrib"   class="input-xlarge" ></td></tr>									
						<tr id="addr1Tr"><td id="addr1Name">额外地址1</td><td><input type="text" name='addr1' id="addr1"  validate="max_length[64]" class="input-xlarge" ></td></tr>
						<tr id="addr2Tr"><td id="addr2Name">额外地址2</td><td><input type="text" name='addr2' id="addr2"  validate="max_length[64]" class="input-xlarge" ></td></tr>
						
						
								
													
						
						
					</table>					
					</form>
         			</div>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger"  id="epAddModal_addbtn">添加</button>
				</div>
</div>
        
<div   class="modal small hide fade" id="CMDAddModal" tabindex="-1" role="dialog" aria-labelledby="CMDAddModal" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="CMDAddModalLabel">命令管理</h3>
				</div>
				<div class="modal-body">
					<div class="form-group smallform-item" align="center">
         			<form id="CMDAddModalform"  name="CMDAddModalform">
					<table class="Boardtab bootstrap-table table table-hover table-striped" hidden="hidden">
					<thead>
					<tr>
					 <th>设备厂商型号</th>
					 <th><input type="text"  name='oemId' id="oemId" class="input-xlarge" readonly disabled="disabled"></th>
					 <th style="display:none"></th>
					 </tr>
					 <tr>
					 <th>选择命令类型</th>
					 <th><select name='cmdctype' id="cmdctype" class="input-xlarge"></select></th>
					 <th style="display:none"><input type="text"  name='cmdepid' id="cmdepid"  style="display:none"></th>
					 </tr>
					
					 
					
					 <tr id="cmddtypeTR" style="display:none">
					 <th>选择设备型号</th>
					 <th><select name='cmddtype' id="cmddtype" class="input-xlarge"></select></th>
					 <th style="display:none"></th>
					 </tr>
					 <tr>
					 <th>选择命令支持的读写操作</th>
					 <th>
					 <select name='cmdrw' id="cmdrw" class="input-xlarge">
					 	<option value="0">read</option>
						<option value="1">write</option>
						<option value="2">read/write</option>
					 </select></th>
					 <th style="display:none"></th>
					 </tr>					
					 </thead>
					</table>
										
					
					<br>
					<h4 id="MCMDtitle" style="float:left;margin-bottom:10px; color:#C22CA3;">模板命令</h4>
									
					<table id="MCMDtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>
                            <th>命令名称</th>
							<th>按键ID</th>
                            <th>命令ID</th>
                            <th>数据类型</th>
                            <th>命令值</th>
							 <th>删除</th>                        
                        </tr>
                    	</thead>						
						<tbody >
                        <tr id="FirstTr">					
							<td><input type="text"  class="input-small" validate="required|max_length[24]" name='name' id="name" ></td>
							<td><input type="text" class="input-small" validate="required|integer" name='id' id="id"></td>
							<td><input type="text" class="input-small" validate="required|integer" name='oid' id="oid"></td>
							<td><input type="text" class="input-small" validate="required|integer" name='dtype' id="dtype" ></td>
							<td><input type="text" class="input-small" validate="required|max_length[128]" name='val' id="val" ></td>
							<td>
                                <a  title="删除"  name="Id" onClick="deleteRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>
					
					<br>
					<h4 style="float:left;margin-bottom:10px; color:#C22CA3;" >自定义命令</h4>
					
					<table id="CMDAddtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>
                             <th>命令名称</th>
							<th>按键ID</th>
                            <th>命令ID</th>
                            <th>数据类型</th>
                            <th>命令值</th>                            
                            <th><a onClick="javascript:addTableRow('CMDAddtable')" title="新增"><i class="icon-plus-sign"></i></a></th>
                        </tr>
                    	</thead>						
						<tbody >
                        <tr id="FirstTr">					
							<td><input type="text"  class="input-small" validate="required|max_length[24]" name='name' id="name" ></td>
							<td><input type="text" class="input-small" validate="required|integer" name='id' id="id"></td>
							<td>
							<input type="text" class="input-small" validate="required|integer" name='oid' id="oid">
							<select style="display:none;" class="input-small" name='oidSelect' id="oidSelect" onChange="CCMDOidChange(this)"></select>
							</td>
							<td><input type="text" class="input-small" validate="required|integer" name='dtype' id="dtype" ></td>
							<td><input type="text" class="input-small" validate="required|max_length[128]" name='val' id="val" ></td>
							<td>
                                <a  title="删除"  name="Id" onClick="deleteCcmdRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>
					
									
					</form>
         			</div>
					
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger"  id="CMDAddModal_addbtn">确定</button>
				</div>
</div>
<div   class="modalTrigger modal small hide fade"   id="TriggerAddModal" tabindex="-1" role="dialog" aria-labelledby="TriggerAddModal" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="TriggerAddModalLabel">联动管理</h3>
				</div>
				<div class="modal-body">
					<div class="form-group smallform-item" align="center">
         			<form id="TriggerAddModalform"  name="TriggerAddModalform">
					<h4 style="float:left; margin-bottom:10px;" id="TriggerAddModalLabel">触发条件配置</h4><br>
															
					<table id="TriggerAddtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>
                            <th  style="display:none;">触发ID</th>
							<th>触发设备</th>
                            <th>命令</th>
                            <th>触发值</th>
                            <th>联动内容配置</th>                           
                            <th><a  id="TriggerRowAddA" onClick="javascript:addTableRow('TriggerAddtable')" title="新增"><i class="icon-plus-sign"></i></a></th>
                        </tr>
                    	</thead>						
						<tbody >
                        <tr >
							<td  style="display:none;">
							<input type="text"  class="input-small" name='rid' id="rid"  value=""  disabled="disabled" readonly="true">
							</td>					
							<td>
							<input type="text" style="display:none;" class="input-small" name='t_epid' id="t_epid"  value="" readonly>
							<input type="text"  class="input-small" name='t_epname' id="t_epname"  value="" readonly>
							</td>	
							<td><select class="input-small" name='oid' id="oid" onchange=GetCurrValGroup(this)></select></td>						
							<td>
							<input type="text"  class="input-small" validate="required" name='val' id="val" onfocus=SetFocusValue(this) onblur=SetBlurValue(this) value=""  readonly="true">
							</td>
							
							
							<td align="center">
                                <a  title="联动内容配置"   onClick="GetReactorFrom(this)"><i class="icon-edit"></i></a>
                            </td>
							<td>
                                <a  title="删除"  onClick="deleteTriggerRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>
					
					<a class="btn btn-danger pull-right"   style="margin-top:8px;" id="TriggerAddModal_addbtn">确定</a>	<br>				
					</form>
					</div>
					<div class="form-group smallform-item" align="center" id="ReactorAddModal" style="display:none">
					<form id="ReactorAddModalform"  name="ReactorAddModalform">
					<h4 style="float:left;margin-bottom:10px;" id="TriggerAddModalLabel">联动配置</h4><br>
					<table class="Boardtab bootstrap-table table table-hover table-striped" >
					<thead>
					 <tr>
					 <th>触发设备</th>
					 <th><input type="text"   name='hepid' id="hepid" class="input-xlarge" readonly></th>
					 </tr>
					 <tr>
					 <th>触发值</th>
					 <th><input type="text"   name='hval' id="hval"  class="input-xlarge" readonly></th>
					 </tr>
					 <tr>
					 <th>命令ID值</th>
					 <th><input type="text"   name='hoid' id="hoid"  class="input-xlarge" readonly></th>
					 </tr>
					 </thead>
					</table>
													
					<table id="ReactorAddtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>
							<th>楼层</th>
                            <th>区域</th> 
                            <th>联动设备</th>
                            <th>命令</th>
                            <th>命令值</th> 
							<th>延迟时间</th>                          
                            <th><a onClick="javascript:addTableRow('ReactorAddtable')" title="新增"><i class="icon-plus-sign"></i></a></th>
                        </tr>
                    	</thead>						
						<tbody >
                        <tr >
                            <td><select class="input-small" name='floorid' id="floorid" onchange=GetCurrAidGroup(this)></select></td>						
							<td><select class="input-small" name='aid' id="aid" onchange=GetCurrEpidGroup(this)></select></td>	
							<td><select class="input-small" name='e_epid' id="e_epid" onchange=GetCurrOidGroup(this)></select></td>						
							<td><select class="input-small" name='oid' id="oid" onchange=GetCurrReactorValGroup(this)></select></td>								
							<td><input type="text" class="input-small" validate="required" name='val' id="val" onfocus=SetReactorFocusValue(this) onblur=SetReactorBlurValue(this) value=""></td>
							<td><input type="text" class="input-small" validate="required|integer" name='delay' id="delay" ></td>
							<td>
                                <a  title="删除"   onClick="deleteRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>
					
					<a class="btn btn-danger pull-right"  style="margin-top:8px;"  id="ReactorAddModal_addbtn">确定</a>					
					</form>
					
         			</div>
					
				</div>
				<div class="modal-footer">
					
				</div>
</div>          
<div  class="modalSence modal small hide fade" id="SceneGroupAddModal" tabindex="-1" role="dialog" aria-labelledby="SceneGroupAddModal" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="SceneGroupAddModalLabel">场景组管理</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form id="SceneGroupAddModalform"  name="SceneGroupAddModalform">
					<div id="SceneGroupDIV">
					<table  id="SceneGroupaddTable">
					<tr >
					<td width="20%"><h6>选择楼层</h6></td>
					<td   align="left" width="25%"><select id="scenFloorid" style="width:150px;" validate="required" class="input-xlarge">	</select></td>
					<td  width="20%"><h6>选择区域</h6></td>
					<td align="left" width="20%"><select id="scenAreaid" style="width:150px;" validate="required" class="input-xlarge">	</select></td>
					<td width="15%"></td>
					</tr>						
					<tr >
					<td  width="20%"><h6>场景组名称</h6></td>
					<td width="25%"><input type="text"  style="width:150px;" name='scenname' id="scenname" validate="required|max_length[24]" class="input-xlarge"></td>
					<td  width="20%"><h6>子场景类型</h6></td>
					<td width="20%"><select id="sceneType" style="width:150px;" validate="required" class="input-xlarge">	</select></td>
					<td width="15%"><a  onClick="javascript:addSceneGroupListtableRow(this)" style="margin-top:-10px;" class="btn-flat success"><i class="icon-plus"></i>添加</a></td>
					</tr>	
					</table>
					<table  id="OtherSceneTypeView" hidden="hidden">
					<tr>
					</tr>
                    <tr >
					<td  width="20%"></td>
					<td width="25%"></td>
					<td  width="20%"></td>
					<td width="20%"><input type="text"  style="width:150px;" name='sceneTypeName' id="sceneTypeName" validate="required|max_length[24]" class="input-xlarge"></td>
					<td width="15%"></td>
					</tr>	
                    
					</table>
					<br></div>
					<h4 id='slistfont' style="float:left;margin-bottom:10px; color:#C22CA3;"  >子场景列表</h4>									
					<table id="SceneGroupListtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>
							<th>子场景ID</th>
                            <th>子场景类型</th>
							<th style="display:none">i</th>
                            <th>删除</th>                          
                        </tr>
                    	</thead>						
						<tbody >
                        
						</tbody>																								
					</table>
									
					</form>
         			</div>
					
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<a class="btn btn-danger"   onClick="AddSceneGroupAction()" id="SceneGroupAddModal_addbtn">确定</a>
				</div>
</div>
<div  class="modalSence modal small hide fade" id="ScenesAddModal" tabindex="-1" role="dialog" aria-labelledby="ScenesAddModal" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="ScenesAddModalLabel">子场景配置</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form >
					<table class="Boardtab bootstrap-table table table-hover table-striped" >
					<thead>
					 <tr>
					 <th>场景组ID</th>
					 <th><input type="text"   name='curscesetid' id="curscesetid" class="input-xlarge" readonly></th>
					 </tr>					
					 </thead>
					</table><br>
					<h4 style="float:left; margin-bottom:10px;color:#C22CA3;"  >子场景列表</h4><br>									
					<table id="ScenesAddModalSceneGroupListtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>
							<th>子场景ID</th>
                            <th>子场景类型</th>
							<th>添加子场景内容</th> 
                                                      
                        </tr>
                    	</thead>						
						<tbody >
                        <tr >
							<td><input type="text"  class="input-small" name='id' id="id"  readonly="true" ></td>
							<td><input type="text"  class="input-small" name='name' id="name" readonly ></td>
								
							<td align="center">
                                &nbsp&nbsp&nbsp
                                <a  title="子场景内容配置"   onClick="GetSceneFrom(this)"><i class="icon-edit"></i></a>
                                &nbsp&nbsp&nbsp
                                <a  title="子场景内容删除"   onClick="DelSonSceneFrom(this)"><i class="icon-remove"></i></a>
                            </td>						
							
						</tr>
						</tbody>																								
					</table>					
					<br>
					<div class="form-group smallform-item" align="center" id="SceneGroupAddDiv" style="display:none">
					<h4 style="float:left;margin-bottom:10px;color:#C22CA3;" >子场景配置</h4><br>
					<table class="Boardtab bootstrap-table table table-hover table-striped" >
					<thead>
					 <tr>
					 <th>子场景类型</th>
					 <th><input type="text"   name='hsceneTypename' id="hsceneTypename" class="input-xlarge" readonly></th>
					 </tr>					
					 </thead>
					</table>
						
					
					<table id="ScenesAddtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>	
                            <th>楼层</th>
                            <th>区域</th>						
                            <th>设备ID</th>
                            <th>命令ID</th>
                            <th>命令值</th>
							<th>延迟时间</th>                           
                            <th><a onClick="javascript:addTableRow('ScenesAddtable')" title="新增"><i class="icon-plus-sign"></i></a></th>
                        </tr>
                    	</thead>						
						<tbody >
                        <tr >	
                            <td><select class="input-small" name='floorid' id="floorid" onchange=GetCurrAidGroup(this)></select></td>						
							<td><select class="input-small" name='aid' id="aid" onchange=GetCurrEpidGroup(this)></select></td>	
							<td><select class="input-small" name='epid' id="epid" onchange=GetCurrOidGroup(this)></select></td>						
							<td><select class="input-small" name='oid' id="oid" onchange=GetCurrReactorValGroup(this)></select></td>								
							<td><input type="text" class="input-small" validate="required|integer" name='val' id="val" onfocus=SetReactorFocusValue(this) onblur=SetReactorBlurValue(this) value="" readonly></td>
							<td><input type="text" class="input-small" validate="required|integer" name='delay' id="delay" ></td>											
							<td>
                                <a  title="删除"   onClick="deleteRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>
						
					</div>					
					</form>
         			</div>
					
				</div>
				<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<a class="btn btn-danger"    id="ScenesAddModal_addbtn">确定</a>
				</div>
</div> 
<div  class="modalAlarm modal small hide fade" id="AlarmAreaAddModal" tabindex="-1" role="dialog" aria-labelledby="AlarmAreaAddModal" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 >报警器分区配置</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form >					
					<h4 style="float:left; margin-bottom:10px;color:#C22CA3;"  >当前报警器分区列表</h4><br>											
					<table id="AlarmAreaAddtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>							
                            <th>分区ID</th>
                            <th>分区名称</th>                                                     
                            <th><a onClick="javascript:addAlarmAreaTableRow('AlarmAreaAddtable')" title="新增"><i class="icon-plus-sign"></i></a></th>
                        </tr>
                    	</thead>						
						<tbody >
                        <tr >												
							<td><input type="text"  class="input-small" validate="required|integer" name='id' id="id" ></td>
							<td><input type="text" class="input-small" validate="required" name='name' id="name"></td>							
							
							<td>
                                <a  title="删除"   onClick="deleteRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>						
									
					</form>
         			</div>
					
				</div>
				<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<a class="btn btn-danger" onClick="AddAlarmAreaAction()" id="AlarmAreaAddModal_addbtn">确定</a>
				</div>
</div>
<div  class="modalAlarm modal small hide fade" id="AlarmAreaZoneAddModal" tabindex="-1" role="dialog" aria-labelledby="AlarmAreaZoneAddModal" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 >当前分区内的防区配置</h3>
				</div>
				<div class="modal-body">
					<div class="form-group" align="center">
         			<form >					
					<h4 style="float:left; margin-bottom:10px;color:#C22CA3;"  >当前分区内的防区列表</h4><br>											
					<table id="AlarmAreaZoneAddtable" class="Boardtab bootstrap-table table table-hover table-striped">
						<thead>
                        <tr>							
                            <th>防区ID</th>
                            <th>防区名称</th>                                                     
                            <th><a onClick="javascript:addAlarmAreaZoneTableRow('AlarmAreaZoneAddtable')" title="新增"><i class="icon-plus-sign"></i></a></th>
                        </tr>
                    	</thead>						
						<tbody >
                        <tr >												
							<td><input type="text"  class="input-small" validate="required|integer" name='id' id="id"></td>
							<td><input type="text" class="input-small" validate="required" name='name' id="name"></td>							
							
							<td>
                                <a  title="删除"   onClick="deleteRow(this)"><i class="icon-remove"></i></a>
                            </td>
						</tr>
						</tbody>																								
					</table>
						
									
					</form>
         			</div>
					
				</div>
				<div class="modal-footer">
				<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<a class="btn btn-danger"    id="AlarmAreaZoneAddModal_addbtn">确定</a>
				</div>
</div>              
<div class="modal small hide fade" id="DeleteAllModal" tabindex="-1" role="dialog" aria-labelledby="DeleteAllModalLabel" aria-hidden="true">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h3 id="DeleteAllModalLabel">删除信息</h3>
				</div>
				<div class="modal-body">
					<p class="error-text"><i class="icon-warning-sign modal-icon"></i>将删除全部已选项，是否确认删除？</p>
				</div>
				<div class="modal-footer">
					<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
					<button class="btn btn-danger" data-dismiss="modal" id="DeleteAllModal_delbtn">删除</button>
				</div>
</div>       
		

  </body>
</html>


